<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
    <my-parent></my-parent>
    </div>
    <template id=comp1>
       <h1>
           我的父组件
           <input type="text" v-model="mytitle">
           <my-child v-bind:title="mytitle" @pchange="doParentChange"></my-child>
        </h1>
    </template>
    <template id=comp2>
    <p>
        <input type="text" v-model="title" @change="doChildChange">
        {{title}}
        我的子组件
    </p>
 </template>
    <script src="js/vue.min.js"></script>
    <script>
    var vm=new Vue({
        el:"#app",
        components:{
            "my-parent":{
                data:function(){
                 return{
                     mytitle:"你好！"
                 }
                },
            template:"#comp1",
            methods:{
                doParentChange:function(changeText)
                {
                    this.mytitle=changeText;
                }
            },
            components:{
                "my-child":{
                    props:["title"],
                    template:"#comp2",
                    methods:{
                        doChildChange:function(){
                            //触发父组件事件
                            this.$emit("pchange",this.title)
                        }
                    }
                }
            }
        }
            }
    })
    </script>
</body>
</html>